<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8">
    <title>分店批发审核</title>
    <meta name="renderer" content="webkit">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
    <link rel="stylesheet" href="/res/layui-v2.5.6/css/layui.css" media="all">
    <!-- 注意：如果你直接复制所有代码到本地，上述css路径需要改成你本地的 -->
    <script type="text/javascript" src="/res/js/jquery-3.4.1.min.js"></script>
    <script type="text/javascript" src="/ok-admin/js/permissionSetting.js"></script>
    <style>
        #myform{
            position: relative;
            top: 15px;
        }
    </style>
</head>
<body>

<form class="layui-form" action="" method="post" lay-filter="myform" id="myform">
    <div class="layui-form-item">
        <div class="layui-inline">
            <label class="layui-form-label">药品名称：</label>
            <div class="layui-input-inline">
                <input type="text" name="drugName" id="drugName" placeholder="请输入药品名称" autocomplete="off" class="layui-input">
            </div>
        </div>

        <div class="layui-inline">
            <label class="layui-form-label">药品类型：</label>
            <div class="layui-input-inline">
                <select name="typeId" id="typeId" lay-search="" autocomplete="off"  lay-filter="aihao">
                    <option value="">选择药品类型</option>
                </select>
            </div>
        </div>

        <div class="layui-inline">
            <div class="layui-input-inline">
                <button class="layui-btn" lay-submit="" lay-filter="search">
                    <i class="layui-icon layui-icon-search"></i>
                </button>
            </div>
        </div>

    </div>
</form>

<table class="layui-hide" id="test" lay-filter="test"></table>




<script type="text/html" id="barDemo">
    <a class="layui-btn layui-btn-xs" lay-event="lookOverDrugInventoryDetail"><i class="layui-icon">&#xe615;</i>查询库存记录</a>
</script>

<script src="/res/layui-v2.5.6/layui.js" charset="utf-8"></script>
<!-- 注意：如果你直接复制所有代码到本地，上述js路径需要改成你本地的 -->

<script>
    var table = null;
    var perUser = null;
    var openIndex = null;
    layui.use(['table','layer'], function(){
        table = layui.table;
        var $ = layui.$;
        var layer = layui.layer;
        let form = layui.form;

        //下拉框赋值
        $.ajax({
            async:false,
            url: '/hqDrugtype/fqueryAll',
            data: '',
            processData: false,
            contentType: false,
            dataType: 'json',
            type: 'GET',
            success: function (obj) {
                $.each(obj,function(index,item){
                    $("#typeId").append(
                        `<option value=${item.typeId}>`+item.typeName+`</option>`
                    );
                });
                console.info(obj)
                //重新渲染
                form.render("select");
            },
            error: function () {

            }
        });

        var url = null;
        var cols = null;
        //判断是否为总公司
        if(returnUser()){
            url = "/hqInventory/showDrugInventoryAll";
            cols = [[
                {field: 'inventoryId', title: '序号', width: 100, fixed: 'left', align: 'center',type: 'numbers',unresize: true, sort: 'true', totalRowText: '合计'}
                , {field: 'drugName', title: '药品名称', align:"center"}
                , {field: 'typeName', title: '药品类型', align:"center"}
                , {field: 'inventoryNum', title: '数量', width: 120, totalRow: true, align:"center"}
                , {field: 'remark', title: '备注', width: 120, align:"center"}
                , {fixed: 'right', title: '查询信息', toolbar: '#barDemo', width: 150, align:"center"}
            ]];
        }else {
            url = "/immRepertory/showDrugInventoryAll";
            cols = [[
                {field: 'repertoryId', title: '序号', width: 100, fixed: 'left', align: 'center',type: 'numbers',unresize: true, sort: 'true', totalRowText: '合计'}
                , {field: 'drugName', title: '药品名称', align:"center"}
                , {field: 'typeName', title: '药品类型', align:"center"}
                , {field: 'count', title: '数量', width: 120, totalRow: true, align:"center"}
                , {fixed: 'right',field: 'remark', title: '备注', width: 120, align:"center"}
                , {fixed: 'right', title: '查询信息', toolbar: '#barDemo', width: 150, align:"center"}
            ]];
        }
        //获取登入用户信息
        var users = JSON.parse(window.localStorage.getItem("users"));
        let roleTable = table.render({
            method: "post"
            ,elem: '#test'
            ,url:  url
            ,title: '用户数据表'
            ,height: 'full-200', cellMinWidth: 80 //最大化适应
            ,height:600
            ,totalRow: true  //开启合计
            ,cols: cols
            ,page: true
            ,id:'testReload'
            , where: function () {
                companyId : users.companyId == "0" ? "0" : users.companyId
            }
        });

        //查询条件
        form.on("submit(search)", function (data) {
            console.info(data)
            roleTable.reload({
                where: data.field,
                page: {curr: 1}
            });
            console.log("0000")
            return false;
        });




        //头工具栏事件
        table.on('toolbar(test)', function(obj){
            var checkStatus = table.checkStatus(obj.config.id);
            switch(obj.event){

                //自定义头工具栏右侧图标 - 提示
                case 'LAYTABLE_TIPS':
                    layer.alert('这是工具栏右侧自定义的一个图标按钮');
                    break;
            };
        });

        //监听行工具事件
        table.on('tool(test)', function(obj){
            var data = obj.data;
            //console.log(obj)
            if(obj.event === 'lookOverDrugInventoryDetail'){
                console.info(data)
                //判断是否为总公司
                let id = null;
                if(users.companyId=='0'){
                    id = data.drugId;
                }else{
                    id = data.drugId;
                }

                openIndex = layui.layer.open({
                    type: 2,
                    area: ['75%', '60%'], //宽高
                    title: '查询库存记录',
                    shift:1,//弹出框动画效果
                    skin: 'layui-layer-molv',//样式
                    shadeClose:true,//点击也能遮罩层关闭
                    shade: [0.8, '#393D49'] ,//显示遮罩
                    maxmin: true, //开启最大化最小化按钮
                    content:`/ok-admin/pages/drugInventory/drugInventoryDetail.html?id=${id}`
                });
            }
        });

    });


</script>

</body>
</html>